Shader "Level4/Reflect/ReflectSelfIllum" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_TintColor("Tint Color",color) = (1,1,1,1)
		_ReflectCube("cube",cube) = ""{}
		_ReflectIntensity("Reflect intensity",float) = 0.3
		_SelfIllumIntensity("self illumination intensity",float) = 0.2
		_BumpMap("BumpMap",2d) = ""{}
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert

		sampler2D _MainTex;
		fixed4 _TintColor;
		samplerCUBE _ReflectCube;
		float _ReflectIntensity;
		float _SelfIllumIntensity;
		sampler2D _BumpMap;

		struct Input {
			float2 uv_MainTex;
			float3 worldRefl;
			INTERNAL_DATA
		};

		void surf (Input IN, inout SurfaceOutput o) {
			half3 norm = UnpackNormal(tex2D(_BumpMap,IN.uv_MainTex));
			half4 ref = texCUBE(_ReflectCube,WorldReflectionVector (IN,norm));
			
			half4 tex = tex2D (_MainTex, IN.uv_MainTex);
			tex *= _TintColor;
			
			half3 increment = ref * 3.0 * saturate(tex.g - 0.25) * (1.0 - tex.a);
			
			o.Albedo = tex.rgb * tex.a * _SelfIllumIntensity;
			o.Albedo += increment;
			
			o.Alpha = 1;
			o.Emission = ref * _ReflectIntensity ;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}
